package com.topsail.demo.context;

/**
 * <B>主类名称：</B><BR>
 * <B>概要说明：</B>用户上下文 Holder<BR>
 *
 * @author steven.zhoulin
 *
 * @since 2023年7月10日 15:36
 */
public final class UserContextHolder {

    private static final ThreadLocal<UserContext> LOOKUP_KEY_HOLDER = ThreadLocal.withInitial(() -> new UserContext());

    private UserContextHolder() {

    }

    static void setUserContext(UserContext userContext) {
        LOOKUP_KEY_HOLDER.set(userContext);
    }

    public static UserContext getUserContext() {
        return LOOKUP_KEY_HOLDER.get();
    }

    public static void clear() {
        LOOKUP_KEY_HOLDER.remove();
    }

}
